package com.taoli.common;

import com.iceolive.util.StringUtil;

import java.util.HashMap;
import java.util.Map;
/**
* @Description: 封装返回数据
* @author: 韦武朝
* @date: 2023/2/16 17:28
*/
public class Result {
    public static final Integer SUCCESS = 200;
    public static final Integer FAILURE = 999;

    private static Map<String,Object> setData(Integer code,String result,String msg,Object data){
        Map<String,Object> map = new HashMap<>();
        map.put("code",code);
        map.put("result",result);
        if(StringUtil.isNotBlank(msg)){
            map.put("msg",msg);
        }
        if(data != null){
            map.put("data",data);
        }
        return map;
    }

    public static Map<String,Object> success(){
        return setData(Result.SUCCESS,"success",null,null);
    }
    public static Map<String,Object> success(Object data){
        return setData(Result.SUCCESS,"success",null,data);
    }
    public static Map<String,Object> failure(){
        return setData(Result.FAILURE,"failure","失败！",null);

    }
    public static Map<String,Object> failure(String msg){
        return setData(Result.FAILURE,"failure",msg,null);
    }
}
